<h1>Thông tin khách hàng</h1>

<table class="table2">
    <tr>
        <td>Họ tên:</td>
        <td><?php echo $customer['Customer']['full_name']; ?></td>
    </tr>
    <tr>
        <td>ĐT:</td>
        <td><?php echo $customer['Customer']['telephone']; ?></td>
    </tr>
    <tr>
        <td>Email:</td>
        <td><?php echo $customer['Customer']['email']; ?></td>
    </tr>
    <tr>
        <td>Địa chỉ:</td>
        <td><?php echo $customer['Customer']['address']; ?></td>
    </tr>
    <tr>
        <td>Mã khách:</td>
        <td><span class="code"><?php echo $customer['Customer']['code']; ?></span></td>
    </tr>
</table>
<p><a href="javascript:history.go(-1)" class="underline"><strong>Quay lại</strong></a></p>

<h2>Lịch sử booking</h2>

<table class="table1">
    <tr>
        <th>Mã booking</th>
        <th>Ngày book</th>
        <th>Khách sạn</th>
        <th>Thời gian</th>
        <th>Đêm phòng</th>
        <th>Tiền phòng</th>
        <th>Tình trạng</th>
        <th>Chi tiết</th>
    </tr>
    <?php foreach ($customer['Booking'] as $booking): ?>
    <?php
    if (empty($booking['alo_exchange_rate']))
    {
        $booking['alo_exchange_rate'] = 1;
    }
    if (empty($booking['Booking']['hotel_exchange_rate']))
    {
        $booking['hotel_exchange_rate'] = 1;
    }
    $total_days = 0;
    $total_price = 0;
    $total_original_price = 0;
    foreach ($booking['BookingDetail'] as $booking_detail)
    {
        $total_days += $booking_detail['days'];
        $total_price += $booking_detail['price'];
        $total_original_price += $booking_detail['original_price'];
    }

    $total_price_usd = 0;
    $total_price_vnd = 0;
    if ($booking['currency'] == 'USD')
    {
        $total_price_usd = $total_price;
        $total_price_vnd = $total_price_usd * $booking['alo_exchange_rate'];

        $total_original_price_usd = $total_original_price;
        $total_original_price_vnd = $total_original_price_usd * $booking['hotel_exchange_rate'];
    }
    else
    {
        $total_price_vnd = $total_price;
        $total_price_usd = $total_price_vnd / $booking['alo_exchange_rate'];

        $total_original_price_vnd = $total_original_price;
        $total_original_price_usd = $total_original_price_vnd / $booking['hotel_exchange_rate'];
    }
    ?>
    <tr>
        <td><?php echo !empty($booking['hotel_booking_code']) ? $booking['hotel_booking_code'] : $booking['alo_booking_code'] ?></td>
        <td><?php echo date('d/m/y', strtotime($booking['date'])) ?></td>
        <td><?php echo $booking['Hotel']['name'] ?></td>
        <td><?php echo date('m/Y', strtotime($booking['date'])) ?></td>
        <td align="right"><?php echo $total_days ?></td>
        <td align="right"><?php echo number_format($total_price_vnd, 1, '.', ',') ?></td>
        <td><?php echo $booking['BookingStatus']['name'] ?></td>
        <td><?php echo $this->Html->link('Xem booking', array('controller' => 'bookings', 'action' => 'show', $booking['id'])); ?></td>
    </tr>
    <?php endforeach; ?>
</table>

<p><a href="javascript:history.go(-1)" class="underline"><strong>Quay lại</strong></a></p>